package com.itboye.sunsun.adapter;

import java.util.List;

import com.itboye.sunsunhome.R;
import com.itboye.sunsun.adapter.LunTanDetailAdapter.ViewHolder;
import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.LunTanHomePageBean.LunTanItemBean;
import com.itboye.sunsun.beans.TieZiSouSuoBean.SouSuoItemBean;
import com.itboye.sunsun.constants.NetPublicConstant;
import com.itboye.sunsun.utils.XImageLoader;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import u.aly.da;

public class TieZiSouSuoAdapter extends BaseAdapter {
	List<SouSuoItemBean> dataList;
	public TieZiSouSuoAdapter(List<SouSuoItemBean> dataList) {
		this.dataList=dataList;
	}

	@Override
	public int getCount() {
		
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		
		return null;
	}

	@Override
	public long getItemId(int position) {
		
		return 0;
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView==null) {
			convertView=LayoutInflater.from(App.ctx).inflate(R.layout.item_sousuo_tiezi, null);
			holder=new ViewHolder();
			holder.name=(TextView) convertView.findViewById(R.id.name);
			holder.content=(TextView) convertView.findViewById(R.id.content);
			holder.time=(TextView) convertView.findViewById(R.id.time);
			holder.zan=(TextView) convertView.findViewById(R.id.zan);
			holder.commont=(TextView) convertView.findViewById(R.id.commont);
			
			holder.head=(ImageView) convertView.findViewById(R.id.head);
			holder.iv1=(ImageView) convertView.findViewById(R.id.iv1);
			holder.iv2=(ImageView) convertView.findViewById(R.id.iv2);
			holder.iv3=(ImageView) convertView.findViewById(R.id.iv3);
			
		 
			holder.imgsContainer=(ViewGroup) convertView.findViewById(R.id.imgsContainer);
			 
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		
		SouSuoItemBean bean=dataList.get(position);
		 if (bean.getUserInfo()==null) {
			 holder.name.setText(bean.getAuthor());
		}else{
			holder.name.setText(bean.getUserInfo().getNickname());
		}
		
		holder.content.setText(bean.getSubject());
		
		holder.time.setText(bean.getDatelineShow());
		holder.zan.setText(bean.getLikes());
		holder.commont.setText(bean.getReplies());
		
		List<String>imgs=bean.getImg();
		holder.iv1.setImageBitmap(null);
		holder.iv2.setImageBitmap(null);
		holder.iv3.setImageBitmap(null);
		if (imgs!=null&&imgs.size()>0) {
			holder.imgsContainer.setVisibility(View.VISIBLE);
			if (imgs.size()>0) {
				XImageLoader.load(NetPublicConstant.IMAGE_URL+imgs.get(0), holder.iv1);
			}
			
			if (imgs.size()>1) {
				XImageLoader.load(NetPublicConstant.IMAGE_URL+imgs.get(1), holder.iv2);
			}
			
			if (imgs.size()>2) {
				XImageLoader.load(NetPublicConstant.IMAGE_URL+imgs.get(2), holder.iv3);
			}
		}else{
			holder.imgsContainer.setVisibility(View.GONE);
		}
		
		try {
			holder.head.setImageBitmap(null);
			XImageLoader.load(NetPublicConstant.IMAGE_URL+bean.getUserInfo().getHead(), holder.head);
		} catch (Exception e) {
		}
		return convertView;
	}

	class ViewHolder{
		
	 
		TextView name;
		TextView content;
		TextView time;
		TextView zan;
		TextView commont;
		ImageView head;
		
		ImageView iv1;
		ImageView iv2;
		ImageView iv3;
		
		 
		ViewGroup imgsContainer;
	}
}
